package com.tiancheng.trade.authserver.component.login;

import com.tiancheng.trade.authserver.enums.LogInTypeEnum;
import com.tiancheng.trade.commom.core.exception.error.AuthErrorInfoEnum;
import com.tiancheng.trade.commom.core.utils.SpringContextHolder;
import org.springframework.stereotype.Component;

/**
 * @Author: likailun
 * @Description: 用户登录工厂
 * @Date: create in 2024/10/22 09:05
 */
@Component
public class UserLoginHandlerFactory {

    /**
     * 获取登录处理器
     *
     * @param logInTypeEnum
     * @return
     */
    public UserLogInHandler getHandler(LogInTypeEnum logInTypeEnum) {
        switch (logInTypeEnum) {
            case Password:
                return SpringContextHolder.getBean("passwordSignInHandler");
            case SmsCode:
                return SpringContextHolder.getBean("smsCodeLoginHandler");
            case Oauth2Password:
                return SpringContextHolder.getBean("oauth2PasswordLogin");
            case WeChatMiniApp:
                return SpringContextHolder.getBean("oauth2PasswordLogin");
            default:
                AuthErrorInfoEnum.AUTH_UN_SUPPORT_LOGIN_METHOD_ERROR.assertFail();
                return null;
        }
    }

}
